package com.laiketui.common.mapper;

import com.laiketui.domain.presell.PreSellRecordModel;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.core.db.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface PreSellRecordModelMapper extends BaseMapper<PreSellRecordModel> {

    /**
     * 查询预售订单列表
     *
     * @param map
     * @return
     * @throws LaiKeAPIException
     */
    List<Map<String, Object>> getSellOrderList(Map<String, Object> map) throws LaiKeAPIException;

    /**
     * 查询预售订单列表数量
     *
     * @param map
     * @return
     */
    int countSellOrderList(Map<String, Object> map);

    /**
     * 预售待付款订单数量
     * @param storeId
     * @param userId
     * @return
     */
    @Select("SELECT p.id FROM lkt_order o LEFT JOIN lkt_pre_sell_record p ON o.sNo = p.sNo WHERE o.store_id = #{storeId} AND o.user_id = #{userId} AND o.`status` = 0 AND o.otype = 'PS'")
    List<Integer> countPending(int storeId, String userId);

    /**
     * 获取定时器需要更新的预售订单
     *
     * @param map -
     * @return List
     * @throws LaiKeAPIException -
     * @author sunH_
     * @date 2020/01/14 15:00
     */
    List<Map<String, Object>> getTimerSellOrder(Map<String, Object> map) throws LaiKeAPIException;

    /**
     * 获取预售商品的预售订单
     *
     * @param productId -
     * @return List
     * @throws LaiKeAPIException -
     * @author sunH_
     * @date 2020/01/14 15:00
     */
    @Select("SELECT p.* FROM lkt_pre_sell_record p LEFT JOIN lkt_order o ON p.sNo = o.sNo WHERE p.product_id = #{productId} AND o.`status` = 0")
    List<Map<String, Object>> getGoodOrder(Integer productId) throws LaiKeAPIException;
}